// 6. VtpGoodsServiceImplPageSearch.java - 商品服务实现
package com.lizheng.yunservice.travel.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizheng.yunservice.common.page.TableDataInfo;
import com.lizheng.yunservice.travel.doamin.bo.VtpGoodsQueryBoPageSearch;
import com.lizheng.yunservice.travel.doamin.vo.VtpGoodsVoPageSearch;
import com.lizheng.yunservice.travel.mapper.VtpGoodsImgMapperPageSearch;
import com.lizheng.yunservice.travel.mapper.VtpGoodsMapperPageSearch;
import com.lizheng.yunservice.travel.service.IVtpGoodsServicePageSearch;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class VtpGoodsServiceImplPageSearch implements IVtpGoodsServicePageSearch {
    private final VtpGoodsMapperPageSearch goodsMapper;
    private final VtpGoodsImgMapperPageSearch goodsImgMapper;

    @Override
    public TableDataInfo<VtpGoodsVoPageSearch> queryAppPageList(VtpGoodsQueryBoPageSearch queryBo) {
        Page<VtpGoodsVoPageSearch> page = goodsMapper.selectAppPage(queryBo.build(), queryBo);
        page.getRecords().forEach(goods ->
                goods.setImgs(goodsImgMapper.selectGoodsImgUrls(goods.getGoodsId(), 1))
        );
        return TableDataInfo.build(page);
    }
}